<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue</title>
    <script src="./vue.js"></script>
    <style>
        #root {
            width: 500px;
            margin: 200px auto;
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="root">
        <!-- 最后一步，编写组件标签 -->
        <xuexiao></xuexiao>
        <hr>
        <xuesheng></xuesheng>
    </div>
    <script>
        Vue.config.productionTip = false

        // 创建组件
        // 组件不能写'el'，data必须写成函数式
        // 创建组件也可以写成一个对象：const components:{options}
        // 组件之间可以套娃，在某个组件的template里加入其他组件就ok
        const school = Vue.extend({
            template: `
            <div>
                <span>学校名称：{{schoolName}}</span>
                <span>学校地址：{{schoolAddress}}</span>
                <button @click='tips'>click me</button>
            </div>
            `,
            data() {
                return {
                    schoolName: 'XAUT',
                    schoolAddress: '雁塔'
                }
            },
            methods: {
                tips() {
                    alert('tips')
                }
            }
        })
        const student = Vue.extend({
                data() {
                    return {
                        studentName: 'chen',
                        studentAddress: '桥洞'
                    }
                },
                methods: {
                    tips() {
                        console.log('123');
                    }
                }
            })
            // 全局注册组件
            // Vue.component('组件名', '调用名')
        Vue.component('student', student)
        const vm = new Vue({
            el: '#root',
            // 注册组件(局部注册)
            components: {
                xuexiao: school,
                xuesheng: student
            },
            computed: {},
            watch: {},
            methods: {},
            directives: {},
        })
    </script>
</body>

</html>